package luanvan.app.foodnote;

import com.actionbarsherlock.app.SherlockFragmentActivity;

import luanvan.app.foodnote.library.ViewPagerAdapter;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.widget.Button;

public class ViewPagerStyleActivity extends SherlockFragmentActivity {
	private ViewPager _mViewPager;
	private ViewPagerAdapter _adapter;
	private Button _btn1,_btn2;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_user_guide);
		
		getSupportActionBar().setIcon(R.drawable.icon_user_guide);
		getSupportActionBar().show();
		
		setUpView();
		setTab();
	}
	private void setUpView() {
		// TODO Auto-generated method stub
		_mViewPager = (ViewPager) findViewById(R.id.viewPager);
		_adapter = new ViewPagerAdapter(getApplicationContext(), getSupportFragmentManager());
		_mViewPager.setAdapter(_adapter);
		_mViewPager.setCurrentItem(0);
		initButton();
	}
	private void initButton() {
		// TODO Auto-generated method stub
		_btn1=(Button)findViewById(R.id.btn1);
    	_btn2=(Button)findViewById(R.id.btn2);
    	setButton(_btn1,"1",20,20);
    	setButton(_btn2,"",10,10);
	}
	private void setTab() {
		// TODO Auto-generated method stub
		_mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int position) {
				// TODO Auto-generated method stub
				btnAction(position);
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}
	protected void btnAction(int action) {
		// TODO Auto-generated method stub
		switch (action) {
		case 0:
			setButton(_btn1,"1",20,20); 
			setButton(_btn2,"",10,10);
			break;

		case 1:
			setButton(_btn2,"2",20,20); 
			setButton(_btn1,"",10,10);
			break;
		}
	}
	private void setButton(Button btn, String text, int h, int w) {
		// TODO Auto-generated method stub
		btn.setWidth(w);
    	btn.setHeight(h);
    	btn.setText(text);
	}
	
	
	
}
